unit uImovel_venda;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uPai, DB, StdCtrls, DBCtrls, Buttons, ExtCtrls, ComCtrls, Mask,
  FacDbEdit, EExtenso;

type
  TfImovel_Venda = class(TfPai)
    Label1: TLabel;
    FacDBEdit1: TFacDBEdit;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label9: TLabel;
    BitBtn1: TBitBtn;
    FacDBEdit2: TFacDBEdit;
    FacDBEdit3: TFacDBEdit;
    FacDBEdit4: TFacDBEdit;
    FacDBEdit7: TFacDBEdit;
    FacDBEdit8: TFacDBEdit;
    FacDBEdit28: TFacDBEdit;
    BitBtn2: TBitBtn;
    DBComboBox2: TDBComboBox;
    Label32: TLabel;
    GroupBox1: TGroupBox;
    Label10: TLabel;
    Label11: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    DBComboBox1: TDBComboBox;
    FacDBEdit9: TFacDBEdit;
    FacDBEdit10: TFacDBEdit;
    FacDBEdit11: TFacDBEdit;
    FacDBEdit12: TFacDBEdit;
    FacDBEdit13: TFacDBEdit;
    FacDBEdit14: TFacDBEdit;
    DBMemo2: TDBMemo;
    DBMemo1: TDBMemo;
    Label30: TLabel;
    Label12: TLabel;
    FacDBEdit15: TFacDBEdit;
    FacDBEdit16: TFacDBEdit;
    BitBtn3: TBitBtn;
    Label13: TLabel;
    GroupBox2: TGroupBox;
    Label14: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    DBEdit13: TDBEdit;
    DBEdit14: TDBEdit;
    DBEdit18: TDBEdit;
    DBEdit19: TDBEdit;
    DBEdit20: TDBEdit;
    DBComboBox3: TDBComboBox;
    DBEdit15: TDBEdit;
    EvExtenso1: TEvExtenso;
    BitBtn4: TBitBtn;
    FacDBEdit5: TFacDBEdit;
    BitBtn7: TBitBtn;
    FacDBEdit6: TFacDBEdit;
    BitBtn8: TBitBtn;
    procedure BitBtn2Click(Sender: TObject);
    procedure btnIncluirClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure DBEdit15Click(Sender: TObject);
    procedure DBEdit15Change(Sender: TObject);
    procedure btnProcurarClick(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fImovel_Venda: TfImovel_Venda;

implementation

uses UDM, uProcurar, uFotoVenda, uPrincipal;

{$R *.dfm}

procedure TfImovel_Venda.BitBtn2Click(Sender: TObject);
begin
  inherited;

 if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsBrowse] then
 begin
  fProcurar:=TfProcurar.Create(self,dm.proc_proprietario);
  try
   fProcurar.TIPO := 'PROPRIETARIO';
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'NOME_PROPRIETARIO';
   fProcurar.btnIncluir.Visible := true;
   if fProcurar.ShowModal=mrOk then
   begin
    if dm.cds_imo_venda.State in [dsBrowse] then
       dm.cds_imo_venda.Edit;
    dm.cds_imo_vendaCOD_PROPRIETARIO.AsInteger := dm.proc_proprietarioCOD_PROPRIETARIO.AsInteger;
    dm.cds_imo_vendaNOME_PROPRIETARIO.AsString := dm.proc_proprietarioNOME_PROPRIETARIO.AsString;
    FacDBEdit1.SetFocus;
   end;
   finally
    dm.proc_proprietario.Close;
    fProcurar.Free;
   end;
 end;

end;

procedure TfImovel_Venda.btnIncluirClick(Sender: TObject);
begin
  inherited;
   BitBtn2.Click;
end;

procedure TfImovel_Venda.BitBtn1Click(Sender: TObject);
begin
  inherited;

 if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsBrowse] then
 begin
  fProcurar:=TfProcurar.Create(self,dm.proc_cep);
  try
   fProcurar.TIPO := 'CEP';
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'RUA';
   fProcurar.btnIncluir.Visible := true;
   if fProcurar.ShowModal=mrOk then
   begin
    if dm.cds_imo_venda.State in [dsBrowse] then
       dm.cds_imo_venda.Edit;
    dm.cds_imo_vendaCOD_ENDERECO.AsInteger := dm.proc_cepCOD_CEP.AsInteger;
    dm.cds_imo_vendaRUA.AsString := dm.proc_cepRUA.AsString;
    dm.cds_imo_vendaUF.AsString := dm.proc_cepUF.AsString;
    dm.cds_imo_vendaCEP.AsString := dm.proc_cepCEP.AsString;
    FacDBEdit3.SetFocus;
    end;
   finally
    dm.proc_cep.Close;
    fProcurar.Free;
   end;
 end;

end;

procedure TfImovel_Venda.BitBtn3Click(Sender: TObject);
begin
  inherited;

  fProcurar:=TfProcurar.Create(self,dm.proc_funcionario);
  try
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'NOME';
   //   fProcurar.btnIncluir.Visible := true;
   if fProcurar.ShowModal=mrOk then
   begin
    if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsBrowse] then
    begin
      if dm.cds_imo_venda.State in [dsBrowse] then
         dm.cds_imo_venda.Edit;
      dm.cds_imo_vendaCOD_FUNCIONARIO.AsInteger := dm.proc_funcionarioCOD_FUNCIONARIO.AsInteger;
      dm.cds_imo_vendaNOME_1.AsString := dm.proc_funcionarioNOME.AsString;
      btngravar.SetFocus;
    end
    else
    begin
      dm.cds_imo_aluguel.Edit;
      dm.cds_imo_aluguelCOD_FUNCIONARIO.AsInteger := dm.proc_funcionarioCOD_FUNCIONARIO.AsInteger;
      dm.cds_imo_aluguelNOME.AsString := dm.proc_funcionarioNOME.AsString;
      btngravar.SetFocus;
    end;
   end;
   finally
    dm.proc_proprietario.Close;
    fProcurar.Free;
   end;

end;

procedure TfImovel_Venda.DBEdit15Click(Sender: TObject);
var
  valor: Double;
begin
  inherited;
  DBEdit14.Text := '';
  if DBEdit15.Text <> ''then
  begin
    valor := StrToFloat(DBEdit15.Text);
    DBEdit14.Text:= EvExtenso1.GetExtenso(Valor);
  end;
end;

procedure TfImovel_Venda.DBEdit15Change(Sender: TObject);
var
  valor: Double;
begin
  inherited;
  DBEdit14.Text := '';
  if DBEdit15.Text <> ''then
  begin
    valor := StrToFloat(DBEdit15.Text);
    DBEdit14.Text:= EvExtenso1.GetExtenso(Valor);
  end;
end;
procedure TfImovel_Venda.btnProcurarClick(Sender: TObject);
begin
  inherited;

  fProcurar:=TfProcurar.Create(self,dm.proc_Imo_venda);
  try
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'NOME_PROPRIETARIO';
//   fProcurar.btnIncluir.Visible := true;
   if fProcurar.ShowModal=mrOk then
    begin
    Dm.cds_imo_venda.Close;
    dm.cds_imo_venda.Params[0].Clear;
    Dm.cds_imo_venda.Params[0].AsInteger:=Dm.proc_Imo_vendaCOD_IMOVENDA.AsInteger;
    Dm.cds_imo_venda.Open;
    end;
   finally
    dm.proc_Imo_venda.Close;
    fProcurar.Free;
   end;

end;

procedure TfImovel_Venda.BitBtn4Click(Sender: TObject);
begin
  inherited;
  if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsBrowse] then
  begin
    fFotoVenda := TfFotoVenda.Create(Application);
    try
      fFotoVenda.ShowModal;
    finally
      fFotoVenda.Free;
    end;
  end;

end;

procedure TfImovel_Venda.BitBtn7Click(Sender: TObject);
begin
  inherited;

 formHondeEstou := 'Imovel_venda';
 if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsbrowse] then
 begin
  fProcurar:=TfProcurar.Create(self,dm.proc_bairro);
  try
   fProcurar.TIPO := 'Bairro';
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'BAIRRO';
   fProcurar.btnIncluir.Visible := True;
   if fProcurar.ShowModal=mrOk then
   begin
    if dm.cds_imo_venda.State in [dsBrowse] then
      dm.cds_imo_venda.Edit;
    if FacDBEdit5.Text = '' then
      dm.cds_imo_vendaBAIRRO.AsString := dm.proc_bairroBAIRRO.AsString;
    FacDBEdit6.SetFocus;
   end;
   finally
    dm.proc_bairro.Close;
    fProcurar.TIPO := '';
    formHondeEstou := '';
    fProcurar.Free;
   end;
 end;
end;

procedure TfImovel_Venda.BitBtn8Click(Sender: TObject);
begin
  inherited;

 formHondeEstou := 'Imovel_venda';
 if dm.cds_imo_venda.State in [dsInsert, dsEdit, dsbrowse] then
 begin
  fProcurar:=TfProcurar.Create(self,dm.proc_cidade);
  try
   fProcurar.TIPO := 'Cidade';
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'CIDADE';
   fProcurar.btnIncluir.Visible := True;
   if fProcurar.ShowModal=mrOk then
   begin
    if dm.cds_imo_venda.State in [dsBrowse] then
      dm.cds_imo_venda.Edit;
    if FacDBEdit6.Text = '' then
      dm.cds_imo_vendaCIDADE.AsString := dm.proc_cidadeCIDADE.AsString;
    FacDBEdit7.SetFocus;
    end;
   finally
    dm.proc_cidade.Close;
    fProcurar.TIPO := '';
    formHondeEstou := '';
    fProcurar.Free;
   end;
 end;
end;

end.
